<template>
    <div class="temp">
        <!--图片详情-->
        <div class="desc">
            <!--图片主题-->
            <div class="title">
                <h3 v-text="imginfo.title"></h3>
                <div>
                    <span>{{imginfo.add_time | datefmt("YYYY-MM-DD HH:mm:ss")}}</span>
                    <span>{{imginfo.click}}次浏览</span>
                </div>
            </div>
            <p class="line"></p>
            <!--缩略图-->
            <div class="imgs">
                <ul class="mui-table-view mui-grid-view mui-grid-9">
                    <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3" v-for="(item, index) in imgs">
                        <img class="preview-img" :src="item.src" height="100" @click="$preview.open(index, imgs)">
                    </li>
                </ul>
            </div>
            <!--图片内容-->
            <div class="content" v-html="imginfo.content"></div>
        </div>
        <!--图片评论-->
        <div class="comment">
            <comment :artid="imgid"></comment>
        </div>
    </div>
</template>

<script>
    import common from "../../kits/common"
    import {Toast} from 'mint-ui';
    import comment from '../../components/subcom/comment.vue'
    export default {
        data() {
            return {
                imgid: 0,
                imginfo: {},
                imgs: []
            }
        },
        created() {
            this.imgid = this.$route.params.imgid;
            this.getImginfo();
            this.getImgs()
        },
        methods: {
            getImginfo(){
                const url = common.apidomain + "/api/getimageInfo/" + this.imgid;
                this.$http.get(url).then((response) => {
                    let body = response.body;
                    if (body.status != 0) {
                        Toast(body.message);
                        return;
                    }
                    this.imginfo = body.message[0];
                });
            },
            getImgs() {
                const url = common.apidomain + "/api/getthumimages/" + this.imgid;
                this.$http.get(url).then((response) => {
                    let body = response.body;
                    if (body.status != 0) {
                        Toast(body.message);
                        return;
                    }
                    this.imgs = body.message.map((item) => {
                        let img = new Image();
                        img.src = item.src;
                        let w = img.width;
                        let h = img.height;
                        return {
                            src: item.src,
                            w: w,
                            h: h
                        }
                    });
                });
            }
        },
        components: {
            comment
        }
    }
</script>

<style scoped>
    .desc .title h3 {
        color: #26d0ff;
        line-height: 1.5em;
    }

    .desc .title div {
        color: #a4a4a4;
        font-size: 14px;
        line-height: 1.2em;
    }

    .desc .content {
        color:#a2a4a4;
        margin-top: 10px;
        line-height: 1.2em;
    }

    .line {
        height: 1px;
        border-bottom: 1px solid #c1c1c1;
        margin: 10px 0;
    }

    .mui-grid-view.mui-grid-9 {
        background-color: #fff;
        border: none;
    }

    .mui-grid-view.mui-grid-9 .mui-table-view-cell {
        border: none;
    }

    .mui-table-view-cell img {
        width: 100px;
        height: 100px;
    }
</style>